package com.gec.web.ajax;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
import com.gec.entity.Buycar;
import com.gec.entity.Member;
import com.gec.service.BuycarService;
import com.gec.service.impl.BuycarServiceImpl;

@WebServlet("/addnum")
public class AddGoodNumServlet extends HttpServlet{

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		resp.setContentType("text/html;charset=utf-8");
		PrintWriter out=resp.getWriter();
		Member member = (Member)req.getSession().getAttribute("member");
		String shopCarId = req.getParameter("shopcarId");
		String shopId = req.getParameter("shopid");
		BuycarService service = new BuycarServiceImpl();
		service.addGoodNumBuyCarId(new Integer(shopCarId));
		int q = service.findById(new Integer(shopCarId));
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("num", q);
		map.put("sum", service.findBuyCarId(new Integer(shopCarId)).getSum());
		map.put("cost", service.cost(member.getId(),new Integer(shopId)));
		map.put("discount", service.discount(member.getId(),new Integer(shopId)));
		map.put("discountprice", service.disCountPrice(member.getId(),new Integer(shopId)));
		String json = JSON.toJSONString(map);
		out.print(json);
		out.close();
		
	}
}
